package GameEngine;


import java.awt.Graphics;

import javax.swing.ImageIcon;


import UserInterface.*;
import Main.*;

/**
 * Boat object.
 */
public class Boat extends RiverObject
{
	private int speed;
	private int HealthLevel;
	private int HealthPercent;
	private ImageIcon ico;
	private int score;
	private boolean jumped;
	private Location location;
	private boolean right;
	private boolean left;
	private boolean forward;
	private boolean back;
	private boolean color;


	private int rotdegree;
	private double jumpTime;
	
	public Boat()
	{
		this.speed = 10;
		this.HealthLevel = 3;
		this.HealthPercent = 100;
		this.ico = GUIManager.images.boatImage;
		this.score = 0;
		this.jumped = false;
		this.location = new Location(400,400);
		this.right = false;
		this.left = false;
		this.forward = false;
		this.back = false;
		this.rotdegree = 0;
		this.jumpTime = 0;
		this.color = false;
	}
	
	/**
	 * Make the boats location righter if the right button has been pressed
	 */
	public void moveRight()
	{
		if (this.right){
			if(this.rotdegree < 16)
				this.rotdegree+=2;
			this.location.setLocation(this.location.getX()+this.speed,this.location.getY());
		}
	}

	/**
	 * Make the boats location lefter if the left button has been pressed
	 */
	public void moveLeft()
	{
		if (this.left){
			if( this.rotdegree > -16)
				this.rotdegree-=2;
			this.location.setLocation(this.location.getX()-this.speed,this.location.getY());
		}
	}
	

	/**
	 * Make the boats location forwarder if the forward button has been pressed
	 */
	public void moveForward()
	{
		if (this.forward){
			if (!this.jumped)
				this.location.setLocation(this.location.getX(),this.location.getY()-this.speed/2);
			else
				this.location.setLocation(this.location.getX(),this.location.getY()-this.speed);
				
		}
	}
	

	/**
	 * Make the boats location backer if the back button has been pressed
	 */
	public void moveBack()
	{
		if (this.back){
			this.location.setLocation(this.location.getX(),this.location.getY()+this.speed);
		}
	}

	/**
	 * Renders the boat on the given graphics object
	 */
	public void renderBoat(Graphics g)
	{
		if (!this.color)
		{
			g.drawImage(Main.GUI.getImages().getBoatImage().getImage(),
					(int)(Main.mygame.getBoat().getLocation().getX()-Math.sin(Main.mygame.getBoat().getJumpTime()*Math.PI/180)*20),
					(int)(Main.mygame.getBoat().getLocation().getY()-Math.sin(Main.mygame.getBoat().getJumpTime()*Math.PI/180)*34),
					(int)(50+Math.sin(Main.mygame.getBoat().getJumpTime()*Math.PI/180)*20),
					(int)(88+Math.sin(Main.mygame.getBoat().getJumpTime()*Math.PI/180)*34),
					null);
		}
		else
		{
			g.drawImage(Main.GUI.getImages().getBoatImage2().getImage(),
					(int)(Main.mygame.getBoat().getLocation().getX()-Math.sin(Main.mygame.getBoat().getJumpTime()*Math.PI/180)*20),
					(int)(Main.mygame.getBoat().getLocation().getY()-Math.sin(Main.mygame.getBoat().getJumpTime()*Math.PI/180)*34),
					(int)(50+Math.sin(Main.mygame.getBoat().getJumpTime()*Math.PI/180)*20),
					(int)(88+Math.sin(Main.mygame.getBoat().getJumpTime()*Math.PI/180)*34),
					null);
		}
	}
	

	/**
	 * Decrease the health percent of the boat by 20
	 * If the health percent is less than 20 it decreases the health level by 1
	 * If the health level is 0 than it makes the game over.
	 */
	public void damaged()
	{
		Main.mygame.getSound().playStone();
		if (this.HealthPercent>20)
		{
			this.HealthPercent -=20;
		}
		else
		{
			if (this.HealthLevel>0)
			{
				this.HealthLevel--;
				this.HealthPercent = 100;
			}
			else
			{
				this.HealthPercent =0;
				Main.mygame.gameOver();
			}
			
		}
	}
	

	/**
	 * Increases the health percent of the boat with respect to given hAmount; if the healthPercent is less than 100
	 * @param hAmount is the given health amount which will be added to healthPercent
	 */
	public void healed(int hAmount)
	{
		Main.mygame.getSound().playGain();
		if (this.HealthPercent<100-hAmount)
		{
			this.HealthPercent +=hAmount;
		}
		else if(this.HealthPercent<100)
		{
			this.HealthPercent = 100;
		}
	}

	
	
	//--------------------------------------------------------------
	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public int getHealthLevel() {
		return HealthLevel;
	}

	public void setHealthLevel(int healthLevel) {
		HealthLevel = healthLevel;
	}

	public int getHealthPercent() {
		return HealthPercent;
	}

	public void setHealthPercent(int healthPercent) {
		HealthPercent = healthPercent;
	}


	public void setIco(ImageIcon ico) {
		this.ico = ico;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public boolean isJumped() {
		return jumped;
	}

	public void setJumped(boolean jumped) {
		this.jumped = jumped;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public boolean isRight() {
		return right;
	}

	public void setRight(boolean right) {
		this.right = right;
	}

	public boolean isLeft() {
		return left;
	}

	public void setLeft(boolean left) {
		this.left = left;
	}

	public boolean isForward() {
		return forward;
	}

	public void setForward(boolean forward) {
		this.forward = forward;
	}

	public boolean isBack() {
		return back;
	}

	public void setBack(boolean back) {
		this.back = back;
	}

	public int getRotdegree() {
		return rotdegree;
	}

	public void setRotdegree(int rotdegree) {
		this.rotdegree = rotdegree;
	}

	public double getJumpTime() {
		return jumpTime;
	}

	public void setJumpTime(double jumpTime) {
		this.jumpTime = jumpTime;
	}
	
	public boolean getColor() {
		return color;
	}


	public void setColor(boolean color) {
		this.color = color;
		if (this.color)
		{
			Main.mygame.getBoat().ico = Main.GUI.getImages().getBoatImage2();
		}
		else
		{
			Main.mygame.getBoat().ico = Main.GUI.getImages().getBoatImage();
		}
			
	}
	
	
}